<script type="text/javascript" src="/js/browser-image-compression.js"></script>
<%- include('nav') %>
  <div class="text-sm breadcrumbs">
    <ul>
      <li>
        <a href="/admin/home">首页</a>
      </li>
      <li>设置</li>
    </ul>
  </div>


  <div id="app" class="clearfix">
    <div class="col col-6 p1 ">
      <div class="card bg-white">
        <div class="card-body">
          <div class="card-title">
            系统设置
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">标题</span>
            </label>
            <input type="text" v-model="env.TITLE" placeholder="<%=process.env.TITLE%>"
              class="input input-sm input-bordered">
          </div>



          <div class="form-control">
            <label class="label">
              <span class="label-text">登录密码</span>
            </label>
            <input type="text" v-model="env.PASSWORD" placeholder="******" class="input input-sm input-bordered">
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">公众号id</span>
            </label>
            <input type="text" v-model="env.FUWUHAOID" placeholder="<%=process.env.FUWUHAOID%>"
              class="input input-sm input-bordered">
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">公众号secret</span>
            </label>
            <input type="text" v-model="env.FUWUHAOSECRET" placeholder="<%=sensitive(process.env.FUWUHAOSECRET)%>"
              class="input input-sm input-bordered">
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">微信商户号</span>
            </label>
            <input type="text" v-model="env.MCHID" placeholder="<%=process.env.MCHID%>"
              class="input input-sm input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">微信支付商户密钥(v2)</span>
            </label>
            <input type="text" v-model="env.MCHKEY" placeholder="<%=sensitive(process.env.MCHKEY)%>"
              class="input input-sm input-bordered">
          </div>



          <!-- <div class="form-control">
          <label class="label">
            <span class="label-text">自定义样式</span>
          </label>
          <textarea type="text"   v-model="env.CSS" placeholder="<%=unescape(process.env.CSS?process.env.CSS:'')%>" class="textarea textarea-sm textarea-bordered"></textarea>
        </div> -->
          <br />
          <div class="card-title">
            更多设置[可空]
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">积分商城首图</span>
            </label>
            <input class="input input-sm input-bordered" type="text" placeholder="<%=process.env.BANNER%>"
              v-model="env.BANNER">
            </input>
            <input type="file" @change="uploadBanner" id="selected-upload-banner" name="" />
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">商城首图跳转链接</span>
            </label>
            <input class="input input-sm input-bordered" placeholder="<%=process.env.BANNERLINK%>"
              v-model="env.BANNERLINK" />
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">页脚链接(默认 /admin/intro)</span>
            </label>
            <input type="text" v-model="env.LANDINGPAGE" placeholder="<%=process.env.LANDINGPAGE%>"
              class="input input-sm input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">页脚文案</span>
            </label>
            <input type="text" v-model="env.FOOTER" placeholder="<%=process.env.FOOTER%>"
              class="input input-sm input-bordered">
          </div>


          <div class="card-actions">
            <button class="btn btn-primary btn-small" @click="saveEnv">保存</button>
          </div>


          <div class="divider"></div>

          <div class="card-title">
            文件上传
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">微信支付商户证书(上传.p12或没显示后缀那个) <%=process.env.MCHPFX%></span>
            </label>
            <input type="file" @change="uploadPfx" id="file-pfx" class="input input-sm  input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">机器人二维码 <%=process.env.BOTQR%></span>
            </label>
            <input type="file" id="file-qr" @change="uploadQr" class="input input-sm  input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">域名授权文件 <%=process.env.VERIFY%></span>
            </label>
            <input type="file" id="file-verify" @change="uploadVerify" class="input input-sm input-bordered">
          </div>

          <div class="mt2">
            <div class="alert alert-warning">
              <label>更新配置后, 请手动首页重启服务,重启期间(10s左右)可能会网页无法正常访问. </label>
            </div>
          </div>


        </div>
      </div>
    </div>




    <div class="col col-6 p1">
      <div class="card bg-white">
        <div class="card-body">
          <div class="card-title">
            话术设置
          </div>
          <div class="form-control">
            <label class="label">
              <span class="label-text">机器人加好友话术</span>
            </label>
            <textarea class="textarea textarea-bordered" rows="6" placeholder="" v-model="main.welcometips">
<%=setting.welcometips%>
          </textarea>
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">机器人加好友图片(可选)</span>
            </label>
            <input class="textarea textarea-bordered" rows="6" placeholder="" v-model="main.welcomeimage">
            </input>

            <input type="file" @change="uploadFile" id="selected-upload-photo" name="" />

          </div>


          <div class="form-control">
            <label class="label">
              <span class="label-text">机器人入群话术</span>
            </label>
            <textarea class="textarea textarea-bordered" rows="3" placeholder="" v-model="main.joinroomtips">
          </textarea>
          </div>




          <div class="form-control">
            <label class="label">
              <span class="label-text">签到话术</span>
            </label>
            <textarea class="textarea textarea-bordered" rows="3" placeholder="" v-model="main.signtips"></textarea>
          </div>


          <div class="form-control">
            <label class="label">
              <span class="label-text">邀请成功话术</span>
            </label>
            <textarea class="textarea textarea-bordered" rows="3" placeholder="" v-model="main.invitetips"></textarea>
          </div>
          <div class="card-actions">
            <button class="btn btn-primary btn-small" @click="saveMain">保存</button>
          </div>


          <div class="divider"></div>

          <div class="card-title">
            收费设定
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">群收费金额</span>
            </label>
            <input type="text" v-model="env.MONTHCHARGE" placeholder="<%=process.env.MONTHCHARGE%>"
              class="input input-sm input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">群收费天数</span>
            </label>
            <input type="text" v-model="env.CHARGEDAYS" placeholder="<%=process.env.CHARGEDAYS%>"
              class="input input-sm input-bordered">
          </div>


          <div class="form-control">
            <label class="label">
              <span class="label-text">红包手续费(%)</span>
            </label>
            <input type="text" v-model="env.REDFEE" placeholder="<%=process.env.REDFEE%>"
              class="input input-sm input-bordered">
          </div>

          <div class="form-control">
            <label class="label">
              <span class="label-text">试用天数, 0关闭(每客户一次)</span>
            </label>
            <input type="text" v-model="env.TRY" placeholder="<%=process.env.TRY%>"
              class="input input-sm input-bordered">
          </div>

          <div class="card-actions">
            <button class="btn btn-primary btn-small" @click="saveEnv">保存</button>
          </div>


        </div>
      </div>
    </div>






  </div>
  <script>
    new Vue({
      el: '#app',
      data: function () {
        return {
          env: {
          },
          main: <%-JSON.stringify(setting) %>
        }
      },
      methods: {
        saveEnv: function () {
          var that = this;
          axios.post('/admin/setting/env', that.env).then(function (res) {
            weui.toast('保存成功');
            location.reload()
          })
        },
        saveMain: function () {
          var that = this;
          axios.post('/admin/setting/main', that.main).then(function (res) {
            weui.toast('保存成功');
            location.reload()

          })
        },

        uploadPfx: function () {
          let that = this;
          var file = document.getElementById('file-pfx').files[0]
          var formData = new FormData();
          formData.append('file', file)
          axios.post('/admin/uploadpfx', formData).then(function (res) {
            weui.toast('上传成功', {
              duration: 500,
              callback: function () {
                location.reload()
              }
            })
          })
        },
        uploadQr: function () {
          let that = this;
          var file = document.getElementById('file-qr').files[0]
          var formData = new FormData();
          formData.append('file', file)
          axios.post('/admin/uploadqr', formData).then(function (res) {
            weui.toast('上传成功', {
              duration: 500,
              callback: function () {
                location.reload()
              }
            })
          })
        },

        uploadVerify: function () {
          let that = this;
          var file = document.getElementById('file-verify').files[0]
          var formData = new FormData();
          formData.append('file', file)
          axios.post('/admin/uploadverify', formData).then(function (res) {
            weui.toast('上传成功', {
              duration: 500,
              callback: function () {
                location.reload()
              }
            })
          })
        },
        uploadFile: function () {
          let that = this;
          var imgfile = document.getElementById("selected-upload-photo").files[0];
          var options = {
            maxSizeMB: 0.8,
            maxWidth: 1000,
          };
          imageCompression(imgfile, options).then(function (compressed) {
            var formData = new FormData();
            formData.append("file", compressed);
            axios.post("/admin/upload", formData).then(function (res) {
              weui.toast("上传成功", { duration: 500 });
              setTimeout(function () {
                that.main.welcomeimage = res.data.path;
              }, 600);
            });
          });
        },

        uploadBanner: function () {
          let that = this;
          var imgfile = document.getElementById("selected-upload-banner").files[0];
          var options = {
            maxSizeMB: 0.8,
            maxWidthOrHeight: 1000,
          };
          imageCompression(imgfile, options).then(function (compressed) {
            var formData = new FormData();
            formData.append("file", compressed);
            axios.post("/admin/upload", formData).then(function (res) {
              weui.toast("上传成功", { duration: 500 });
              setTimeout(function () {
                that.env.BANNER = res.data.path;
              }, 600);
            });
          });
        },

      }
    })
  </script>